package com.d3works.apps.supplychain.service.config;

import com.d3works.apps.base.db.Company;
import com.d3works.apps.supplychain.db.SupplyChainConfig;
import com.d3works.apps.supplychain.exception.SupplychainExceptionMessage;
import com.d3works.exception.D3worksException;
import com.d3works.exception.db.repo.TraceBackRepository;
import com.d3works.i18n.I18n;

public class SupplyChainConfigServiceImpl implements SupplyChainConfigService {

  @Override
  public SupplyChainConfig getSupplyChainConfig(Company company) throws D3worksException {

    SupplyChainConfig supplyChainConfig = company.getSupplyChainConfig();

    if (supplyChainConfig == null) {

      throw new D3worksException(
          company,
          TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
          I18n.get(SupplychainExceptionMessage.SUPPLY_CHAIN_CONFIG),
          company.getName());
    }

    return supplyChainConfig;
  }
}
